export function tree(dataList) {
  const formatObj = dataList.reduce((pre, cur) => {
    return { ...pre, [cur['id']]: cur }
  }, {})

  const formatArray = dataList.reduce((arr, cur) => {
    const pid = cur.pid ? cur.pid : 0
    const parent = formatObj[pid]
    if (parent) {
      parent.children ? parent.children.push(cur) : (parent.children = [cur])
    } else {
      arr.push(cur)
    }
    return arr
  }, [])

  return formatArray
}
